<template>
	<view class="alllogin">
		<!-- <view class="iconview"> -->
			<image class="logo" src="../../static/logo.png"></image>
		<!-- </view> -->
		
		<input type="text" class="logininput" placeholder="请输入用户名" v-model="username" maxlength="10"/>
		<input type="text" class="logininput" placeholder="请输入密码" v-model="password" maxlength="10"/>
		<button class="login" @click="login()">登陆</button>
		
		<navigator url="./register" hover-class="navigator-hover" class="gotoregister">
			<text>还没有账号？点击注册</text>
		</navigator>
		<text v-model="tips">{{tips}}</text>

		
		
		
	</view>
</template>

<script>
	export default{
		data(){
			return{
				username:"",
				password:"",
				tips:"",
			}
		
	},
	methods:{
		login(){
			if(this.username=="" || this.password==""){
				uni.showToast({
					title:"请输入完整",
					icon:"none"
				})
			}
			else{
			uni.showLoading({
			    title: '正在登陆'
			});
			uni.request({
				url:getApp().globalData.http+"/user/login",
				method:"POST",
				header:{
					'content-type':"application/x-www-form-urlencoded",
					
					
				},
				data:{
					username:this.username,
					password:this.password,
				},
				// sslVerify: false,
				success: (res) => {
					this.tips=res.data.username
					if(res.data=="no_user"){
						uni.showToast({
						title: '没有该用户',
						icon:'none',
						duration: 1000
						});
					}
					else if(res.data=="pwd_error"){
						uni.showToast({
						title: '密码错误',
						icon:'none',
						duration: 1000
						});
					}
					else{
						uni.setStorageSync("token",res.data.uuid);
						uni.setStorageSync("username",res.data.username);
						uni.setStorageSync("iconpath",res.data.iconpath);
						uni.setStorageSync("nicheng",res.data.nicheng);
						uni.setStorageSync("phone",res.data.phone);
						uni.hideLoading();
						var page=getCurrentPages().length-2;
						uni.navigateBack({
							delta:page
						})
						uni.showToast({
							title:"登陆成功",
							duration:1000,
						})
						getApp().firstlogin="true";
					}
					
					
                    
					
				}
				
			})
			}
		}
	}
	
}
</script>

<style scoped>
	.alllogin{
		height: 100%;
		background-color: #FFFFFF;
		overflow: hidden;
		
		width: 300;
		/* margin: 15px; */
		/* border-radius: 15px; */
		display: flex;
		flex-direction: column;
		align-items: center;
		
	}
	.logo{
		width: 95px;
		height: 90px;
		margin-top: 100px;
	}
/* 	.iconview{
		
		background-color: #FFFFFF;
		width: 300;
		margin: 15px;
		height: 300px;
		border-radius: 15px;
		display: flex;
		flex-direction: column;
		align-items: center;
		overflow: hidden;
	} */
	.logininput{
		
		border: none;
		background-color: #F4F4F4;
		width: 300px;
		height: 40px;
		border-radius: 15px;
		margin-top: 20px;
		padding-left: 10px;
		font-size: 15px;
	}
	
	.login{
		width: 150px;
		height: 40px;
		background-color: #FF8C00;
		border-radius: 70px;
		text-align: center;
		vertical-align:middle;
		line-height: 40px;
		margin-top: 60px;
	}
	.gotoregister{
		margin-top: 10px;
	}
	
</style>
